#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>
#define R 900
#ifdef __cplusplus
    #define __CPPARGS ...
#else
    #define __CPPARGS
#endif

int gx;
void interrupt handler(__CPPARGS)
{
	static int y=480;
	circle(gx,y-R,R);
	y=y-y/12;
	if(y<30)	{
		y=480;
		gx+=10;
	}
}

#define PIT_INIT_COMMAND 0x36
#define PIT_CONTROL 0x43
#define PIT_CNTR0 0x40
#define PIT_HZ 1193182
void debug(int value)
{
	printf("\nDEBUG: %d",value);
	getch();
}

void setclock(int hz)
{
	unsigned int divisor=PIT_HZ/hz;
	debug(divisor);
	outp(PIT_CONTROL,PIT_INIT_COMMAND);
	outpw(PIT_CNTR0,divisor);
}

void main()
{
	int x,y=480,gdriver=DETECT,gmode;
	//initgraph(&gdriver,&gmode,"");
	setvect(0x1c,handler);
	setclock(20);
	gx=0;
	setbkcolor(0);
	setcolor(6);
	delay(2000);
	getch();
}